package com.lanou3g.code0416;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * Created by dllo on 18/4/16.
 */
public class Test04 {
    public static void main(String[] args) {
       //save();
        load();



    }

    private static void load(){
       FileInputStream fis = null;
        ObjectInputStream ois = null;

        try {
            fis = new FileInputStream("person");
            ois = new ObjectInputStream(fis);

            Person o = (Person) ois.readObject();

            System.out.println(o.getName());
            System.out.println(o.getAge());

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeAll(ois);
        }
    }

    private static void save() {
        FileOutputStream fos = null;

        ObjectOutputStream oos = null;
        Person person = new Person();
        person.setName("张三");
        person.setAge(12);

        try {
            fos = new FileOutputStream("person");
            oos = new ObjectOutputStream(fos);

            oos.writeObject(person);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeAll(oos);
        }
    }
}

